export class ColorTransform {
    public constructor(
        public aM: number = 100,
        public rM: number = 100, public gM: number = 100, public bM: number = 100,
        public aO: number = 0,
        public rO: number = 0, public gO: number = 0, public bO: number = 0
    ) {
    }

    public toString(): string {
        return `${this.aM}_${this.rM}_${this.gM}_${this.bM}_${this.aO}_${this.rO}_${this.gO}_${this.bO}`;
    }

    public toFixed(): void {
        this.aM = Math.round(this.aM);
        this.rM = Math.round(this.rM);
        this.gM = Math.round(this.gM);
        this.bM = Math.round(this.bM);
        this.aO = Math.round(this.aO);
        this.rO = Math.round(this.rO);
        this.gO = Math.round(this.gO);
        this.bO = Math.round(this.bO);
    }

    public copyFrom(value: ColorTransform): void {
        this.aM = value.aM;
        this.rM = value.rM;
        this.gM = value.gM;
        this.bM = value.bM;
        this.aO = value.aO;
        this.rO = value.rO;
        this.gO = value.gO;
        this.bO = value.bO;
    }

    public copyFromRGBA(value: number): void {
        this.rM = Math.round(((0xFF000000 & value) >>> 24) / 255 * 100);
        this.gM = Math.round(((0x00FF0000 & value) >>> 16) / 255 * 100);
        this.bM = Math.round(((0x0000FF00 & value) >>> 8) / 255 * 100);
        this.aM = Math.round((0x000000FF & value) / 255 * 100);
    }

    public identity(): void {
        this.aM = this.rM = this.gM = this.bM = 100;
        this.aO = this.rO = this.gO = this.bO = 0;
    }

    public equal(value: ColorTransform): boolean {
        return this.aM === value.aM && this.rM === value.rM && this.gM === value.gM && this.bM === value.bM &&
            this.aO === value.aO && this.rO === value.rO && this.gO === value.gO && this.bO === value.bO;
    }
}